package com.mall.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.github.pagehelper.PageHelper;
import com.mall.entity.OmsOrderReturnReason;
import com.mall.mapper.OmsOrderReturnReasonMapper;
import com.mall.service.OmsOrderReturnReasonService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 退货原因表 服务实现类
 * </p>
 *
 * @author zzx
 * @since 2022-06-15
 */
@Service
public class OmsOrderReturnReasonServiceImpl extends ServiceImpl<OmsOrderReturnReasonMapper, OmsOrderReturnReason> implements OmsOrderReturnReasonService {

    @Autowired
    private OmsOrderReturnReasonMapper omsOrderReturnReasonMapper;

    @Override
    public int create(OmsOrderReturnReason returnReason) {
        returnReason.setCreateTime(new Date());
        return save(returnReason) ? 1 : 0;
    }

    @Override
    public int update(Long id, OmsOrderReturnReason returnReason) {
        return update(returnReason, new UpdateWrapper<OmsOrderReturnReason>().eq("id",id)) ? 1 : 0;
    }

    @Override
    public int delete(List<Long> ids) {
        QueryWrapper<OmsOrderReturnReason> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("id", ids);
        return remove(queryWrapper) ? 1 : 0;
    }

    @Override
    public List<OmsOrderReturnReason> list(Integer pageSize, Integer pageNum) {
        PageHelper.startPage(pageNum, pageSize);
        return list(new QueryWrapper<OmsOrderReturnReason>().orderByDesc("id"));
    }

    @Override
    public int updateStatus(List<Long> ids, Integer status) {
        if(!status.equals(0)&&!status.equals(1)){
            return 0;
        }
        QueryWrapper<OmsOrderReturnReason> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("id", ids);
        OmsOrderReturnReason omsOrderReturnReason = new OmsOrderReturnReason();
        omsOrderReturnReason.setStatus(status);
        return update(omsOrderReturnReason, queryWrapper) ? 1 : 0;
    }

    @Override
    public OmsOrderReturnReason getItem(Long id) {
        return getById(id);
    }
}
